package com.tencent.cloud.iov.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author vinsonhuang
 * @date 2018/6/25
 */
public class TimeUtils {

    private static final String YMD = "yyyy-MM-dd";

    private static final String YMD_HMS = "yyyy-MM-dd HH:mm:ss";

    public static String getCurrentTimeOfYMD() {
        SimpleDateFormat sdf = new SimpleDateFormat(YMD, Locale.CHINA);
        return sdf.format(new Date());
    }

    /**
     * 左边添加0
     */
    public static String addLeftZero(int tempNum) {
        String num;
        if (tempNum < 10) {
            num = "0" + tempNum;
        } else if (tempNum == 0) {
            num = "00";
        } else {
            num = "" + tempNum;
        }

        return num;
    }

    public static String transSecondsToMS(int time) {
        String tem;
        if (time > 0) {
            int minute = time / 60;
            int second = time % 60;
            tem = TimeUtils.addLeftZero(minute) + ":" + TimeUtils.addLeftZero(second);
        } else {
            tem = "00:00";
        }
        return tem;
    }
}
